
local style = {};
Style = {};
style["simple"] = {
render = 
function(button)
    local width = button.width;
    local height = button.height;
    local x = button.x;
    local y = button.y;
    local color = 0xFFD3D5D4;
    --button:SetRndererTarget()
    if(button.renderState~=button.focus)then
        button.state = "rendering";
        button.renderState = button.focus;
    end
    if(button.text and button.renderText~=button.text)then
        print(22333333);
        button.state = "rendering";
        button.renderText = button.text;
    end
    if(button:LockRender())then 
        if(button.focus=="m")then
            color = 0xFFE3E5E4;
            print(color);
        elseif(button.focus=="md")then
            color = 0xFFC3C5C4;
        end
        drawRect(0,0,width,height,color + 0x101010,true);
        drawRect(0,0,width,height,color);
        if(button.text)then
            drawString(button.text,button.width,button.height);
        end
        button:UnlockRender();
    end
end,
};


function Style.button(widget,name)
    if(name==nil)then name = 'simple';end;
    local oldrender = widget.render;
    widget.render = function(self)
        local s = style[name];
        s.render(self);
        oldrender(self);
    end
    widget.mousemotion = function(self,event)
        local x =  event.x;
        local y =  event.y;
        if(x>=self.x and x<=(self.x+self.width) and y>=self.y and y<=(self.y+self.height))then
            if(self.focus~="md")then
                self.focus = "m";
            end
            return true;
        else
            self.focus = nil;
        end
    end
    widget.mousebuttondown = function(self,event)
        local x = event.x;
        local y = event.y;
        if(x>=self.x and x<=(self.x+self.width) and y>=self.y and y<=(self.y+self.height))then
            self.focus = "md";
            print(x,y);
            return true;
        else
            self.focus = nil;
        end
        
    end
    widget.mousebuttonup = function(self,event)
        local x =  event.x;
        local y =  event.y;
        if(x>=self.x and x<=(self.x+self.width) and y>=self.y and y<=(self.y+self.height))then
            self.focus = "m";
            self.text = "点击" .. x;
            return true;
        else
            self.focus = "mu";
        end
    end
end

